<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>
<%@ page import ="com.easyattendance.services.AddSectionService" %>
<%@ page import ="com.easyattendance.model.Section" %>
<html>
<head>
<title>Admin - Section Settings</title>
<!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> -->
<jsp:include page="../includeFiles.jsp" ></jsp:include>
<script src="<%=request.getContextPath()%>/public/js/validate.js"></script>

<link rel="stylesheet" href="<%=request.getContextPath()%>/views/css/ui/jquery-ui-1.10.4.custom.min.css">
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.core.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.widget.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.accordion.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.datepicker.js"></script>
<script>
	/* If want to fix height inner content of accordion - 
	remove 'heightStyle' line (and the above comma too :p ).
	*/
	$(function() {
		$( "#accordion" ).accordion({
			collapsible: true,
			heightStyle: "content",
		});
	});
	var i=1;
	
	function start_date(i){
		$(function() {
			
			$( "#term_start_date"+i ).datepicker({
				defaultDate: "+1w",
				changeMonth: true,
				numberOfMonths: 1,
				dateFormat: 'yy-mm-dd',
				beforeShowDay: noSunday,
				onClose: function( selectedDate ) {
					$( "#term_end_date"+i ).datepicker( "option", "minDate", selectedDate );
				}
			});
			$( "#term_end_date"+i ).datepicker({
				defaultDate: "+1w",
				changeMonth: true,
				numberOfMonths: 1,
				dateFormat: 'yy-mm-dd',
				beforeShowDay: noSunday,
				onClose: function( selectedDate ) {
					$( "#term_start_date"+i ).datepicker( "option", "maxDate", selectedDate );
				}
			});
		});
	}
	function noSunday(date){ 
        return [date.getDay() != 0, ''];
    };
</script>

</head>

<!--
		Note: Set the body element's class to "left-sidebar" to position the sidebar on the left.
		Set it to "right-sidebar" to, you guessed it, position it on the right.
	-->
<body class="left-sidebar">

<!-- Session check : user logged in or not/ press back button -->
<jsp:include page="../common/checkSession.jsp"></jsp:include>
<jsp:include page="../common/checkAdminRole.jsp" />

	<!-- Wrapper -->
	<div id="wrapper">

		<!-- Content -->
		<div id="content">
			<div id="content-inner">

				<span class="success_msg">${section_update_successfull}</span>
				<span class="error_msg">${section_update_not_successfull}</span>
				<span class="success_msg">${section_delete_successfull}</span>
				<span class="error_msg">${section_delete_not_successfull}</span>
				<span class="error_msg">${section_invalid_selection}</span>


				<div>
					<form action="<%=request.getContextPath()%>/views/admin/addSection.jsp">
						<input type="submit" value="Add Section" class="button add_button" tabindex="1">
					</form>
				</div>
				<div id="accordion" style="clear:both;">
				<%	AddSectionService addSectionService = new AddSectionService();	
					List<Section> sectionList = new ArrayList<Section>();
					sectionList = addSectionService.listSections();
					Section tempSection = null;
					Iterator sectionItr = sectionList.iterator();
					int i=0;
					
					while(sectionItr.hasNext()) { i++; %>
						<h3> <% try {
									tempSection = (Section) sectionItr.next();
								} 
								catch(Exception ex){
									ex.printStackTrace();
								}%> 
								
							<%= tempSection.getSection_name() %>
						</h3>
						<div>
						
							<div>
								<form name="sectionDeleteForm<%=i%>" action="${pageContext.request.contextPath}/AddSectionServlet" method="post">
									<input type="submit" value="" class="delete_button" alt="Delete">
									<input type="hidden" id="section_email<%=i%>" name="section_email<%=i%>" value="<%= tempSection.getEmail_id() %>" >
									<input type="hidden" id="action_type" name="action_type" value="delete">
									<!-- <input type="hidden" id="type" name="type" value="section"> -->
									<input type="hidden" id="i_value" name="i_value" value=<%=i%>>
								</form>
							</div>
							<form name="sectionUpdateForm<%=i%>" action="${pageContext.request.contextPath}/AddSectionServlet" method="post">
								
								<div>
									<input type="hidden" value="<%= tempSection.getSection_id() %>" >
									<input type="hidden" id="action_type" name="action_type" value="update">
									<input type="hidden" id="i_value" name="i_value" value=<%=i%>>
								
								
									<div id="dataForm">
										<label>Name:</label>
										<input type="text" id="section_name<%=i%>" name="section_name<%=i%>" value="<%=tempSection.getSection_name()%>" >
									</div>
									
									<div id="dataForm">
										<label>Email:</label>
										<input type="text" id="section_email<%=i%>" name="section_email<%=i%>" value="<%= tempSection.getEmail_id() %>" readonly="readonly">
									</div>
									<div id="dataForm">
										<label>Term start date:</label>
										<input type="text" id="term_start_date<%=i%>" name="term_start_date<%=i%>" value="<%= tempSection.getTerm_start_date() %>" onfocus="start_date(<%=i%>)">
									</div>
									<div id="dataForm">
										<label>Term end date:</label>
										<input type="text" id="term_end_date<%=i%>" name="term_end_date<%=i%>" value="<%= tempSection.getTerm_end_date() %>">
									</div>
									
									<div>
										<input type="submit" value="Save" class="button add_button" >
									</div>
								</div>
							</form>
						</div>
					<% } %>
				</div>
				
			</div>
		</div>

		<!-- Sidebar -->
		<div id="sidebar">

			<!-- Sidebar Header - Logo & Name -->
			<%@include file="../common/sidebarHeader.jsp" %>

			<jsp:include page="adminMenu.jsp" />

			<!-- Sidebar Footer Content -->
			<%@include file="../common/sidebarFooter.jsp" %>

		</div>

	</div>
	<script type="text/javascript">
		$(function(){
			$("#sectionSettings").addClass("current_page_item");
		});
	</script>
	

</body>
</html>